home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / utility / ffe101.zip / SOUND.SWG / 0004_INS BNK.pas < prev    next >
Pascal/Delphi Source File  |  1996-09-04  |  6KB  |  154 lines

  1. Ad Lib, January 1989
  2. --------------------
  3.  
  4. The  .INS  instrument files have been  grouped together to create a .BNK
  5. (bank)  file. The purpose of this is to save space. DOS will allocate 1K
  6. of space for a file regardless of how small the file actually is. So the
  7. bank file saves a significant amount of space.
  8.  
  9. We  are currently modifying our software to use the .BNK file instead of
  10. .INS  files. The new software versions will all be numbered 1.5 and will
  11. not  support the old .INS files. However,  a utility will be provided to
  12. convert  between the two formats. The default  name for the bank file is
  13. STANDARD.BNK although any name may be used as long as the file extension
  14. is .BNK.
  15.  
  16. The  .BNK file a basically a collection  of the old .INS file structures
  17. (as  shown  in Appendix C of  the Programmer's Manual) with the waveform
  18. added to the end.
  19.  
  20.  
  21. Structure of .BNK files
  22. -----------------------
  23.  
  24. FIELD#  SIZE-bytes  TYPE        DESCRIPTION
  25.  
  26. HEADER
  27. 1       1           char        file version, major
  28. 2       1           char        file version, minor
  29. 3       6           char        signature: "ADLIB-"
  30. 4       2           unsigned    number of list entries used
  31. 5       2           unsigned    total number of list entries in file
  32. 6       4           long        absolute offset in file of start of name list
  33. 7       4           long        absolute offset in file of start of data
  34. 8       8           char        filler (set to zero)
  35.  
  36. INSTRUMENT NAME SECTION RECORD
  37. 1          2           unsigned    index into data section
  38. 2          1           char        flag: 0 if this record is not used, else 1
  39. 3          9           char        instrument name (max 8 char + NULL)
  40.  
  41. DATA SECTION RECORD
  42. 1       1           char        mode (0=melodic, 1=percussive)
  43. 2       1           char        voice number (if percussive mode)
  44. 3       13          char        modulator (operator 0) parameters
  45. 4       13          char        carrier (operator 1) parameters
  46. 5       1           char        wave form for modulator
  47. 6       1           char        wave form for carrier
  48.  
  49.  
  50. There  is one header at the very beginning  of the file. Field #6 in the
  51. header  is  the  absolute  offset of  the  start  of the instrument name
  52. section.
  53.  
  54. The instrument name section contains a list of records which contain the
  55. instrument  name, a flag and a pointer to the data section. Header field
  56. #5  gives the total number of records  in this list, although not all of
  57. these  records  may be in use. Header  field #4 gives the number of name
  58. records which are actually being used. The records in use will be placed
  59. at  the beginning of the section  and will be arranged alphabetically by
  60. instrument name.
  61.  
  62. The  data section contains the records  of instrument parameters. One of
  63. these  records is equivalent to the .INS file structure, except that the
  64. 2-byte  fields  are now 1-byte long. Two  more bytes have been added for
  65. the wave form type for each operator.
  66.  
  67. So, to read an instrument from the new bank file:
  68. 1. Read the header.
  69. 2. Use header field #6 to do a seek to the start of the instrument name
  70.    section.
  71. 3. Search the name section for the desired name.  (The search is delimited
  72.    by header field #4.)
  73. 4. When found, get its index into the data section (name field #1).
  74. 5. Calculate the address where the data for this instument will be found:
  75.       header_field_#7 + (index * sizeof_data_record)
  76. 6. Do a seek to the calculated address and read the data.
  77.  
  78.  
  79. Notes
  80. -----
  81.  
  82. The  instrument  names are alphabetically arranged  so  that you are not
  83. limited  to  using  a  linear search  method.  A  binary search would be
  84. appropriate.
  85.  
  86. If  you  are  going to be creating  or  deleting an instrument, you must
  87. preserve  the alphabetical order of  instrument names. However, the data
  88. section  is not neccesarily ordered. When  adding data, you can find the
  89. data  record  to  use  from  the  index  pointer  from  the first unused
  90. instrument name record.
  91.  
  92. The  unused instrument name records are not empty: the pointers into the
  93. data  section  are  valid  and are  used  when  adding instruments. When
  94. expanding the instrument name section, field #1 must be initialized to a
  95. valid  value.  (In this case, the data  section must be shifted down and
  96. header  field  #7 must be adjusted  accordingly.)  The purpose of having
  97. empty  name records is to avoid having  to rewrite the entire file every
  98. time an instrument is added.
  99.  
  100.  
  101. C   Structures  ------------  The  following   are  C  structures  which
  102. correspond to the information given above.
  103.  
  104.  
  105. /* Instrument bank file header */
  106. typedef struct {
  107.    char      majorVersion;
  108.    char      minorVersion;
  109.    char      sig [6];            /* signature: "ADLIB-" */
  110.    unsigned  nrDefined;          /* number of list entries used */
  111.    unsigned  nrEntry;            /* number of total entries in list */
  112.    long      offsetIndex;        /* offset in file of start of name list */
  113.    long      offsetTimbre;       /* offset in file of start of data */
  114.    char      filler [8];         /* must be zero */
  115. } BankHeader;
  116.  
  117.  
  118. /* Name of instrument with a pointer to its position in the file */
  119. typedef struct {
  120.    unsigned nrReference;       /* index into data section */
  121.    char  usedFlag;             /* 0 if this entry is not used */
  122.    char  TimbreName [9];       /* max 8 char's + NULL */
  123. } BankEntry;
  124.  
  125.  
  126. /* Operator structure */
  127. typedef struct {
  128.    char  ksl;
  129.    char  freqMult;
  130.    char  feedBack;              /* used by operator 0 only */
  131.    char  attack;
  132.    char  sustLevel;
  133.    char  sustain;
  134.    char  decay;
  135.    char  release;
  136.    char  output;
  137.    char  am;
  138.    char  vib;
  139.    char  ksr;
  140.    char  fm;                    /* used by operator 0 only */
  141. } Operator;
  142.  
  143.  
  144. typedef struct {
  145. char      mode;
  146. char      percVoice;
  147. Operator  op0;
  148. Operator  op1;
  149. char      wave0;            /* wave form for operator 0 */
  150. char      wave1;            /* wave form for operator 1 */
  151. } PackedTimbre;
  152.  
  153.  
  154.